package com.gimi.cloud.jimi.client.controller.userInfo;

import com.gimi.cloud.jimi.client.service.userInfo.RdFaceInfoService;
import com.gimi.cloud.jimi.common.enums.ResponseCodeEnum;
import com.gimi.cloud.jimi.common.utils.JsonUtil;
import com.gimi.cloud.jimi.common.utils.oss.AliOSSUtil;
import com.gimi.cloud.jimi.common.utils.reqhead.Response;
import com.gimi.cloud.jimi.common.utils.reqhead.Util;
import com.gimi.cloud.jimi.dto.userInfo.RdFaceInfoDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;

@RestController
@RequestMapping(value = "faceInfo")
public class FaceInfoController {
    @Autowired
    private RdFaceInfoService rdFaceInfoService;

    @RequestMapping(value = "/saveFaceInfo")
    public void saveFaceInfo(@RequestBody  RdFaceInfoDTO param, HttpServletResponse response) {
        Response resp = new Response();
        param.setImage(AliOSSUtil.getFilePath(param.getImage()));
        rdFaceInfoService.saveFaceInfo(param);
        resp.setResponseCode(ResponseCodeEnum.SUCCESSED);
        Util.sendResponse(JsonUtil.toJson(resp), response);
    }

    @RequestMapping(value = "/getFaceInfo")
    public void getFaceInfo(@RequestBody  RdFaceInfoDTO param, HttpServletResponse response) {
        Response resp = new Response();
        RdFaceInfoDTO dto = rdFaceInfoService.getFaceInfoByUser(param.getUserId());
        resp.setRes_data(dto);
        resp.setResponseCode(ResponseCodeEnum.SUCCESSED);
        Util.sendResponse(JsonUtil.toJson(resp), response);
    }
}
